//
//  ChooseLevelScene.cpp
//  Frog Jump
//
//  Created by acumen on 7/26/13.
//
//

#include "ChooseLevelScene.h"

USING_NS_CC;
using namespace extension;

bool ChooseLevelScene::init() {
    if (!CCLayer::init()) {
        return false;
    }
    int numberOfLevel = GameController::getNumberOfLevel();
    CCSize winSize = GameController::getWinSize();
    // Background
    CCSprite *pSpriteBackground = CCSprite::create(IMG_BACKGROUND_IPHONE_HD);
    pSpriteBackground->setAnchorPoint(CCPointZero);
    pSpriteBackground->setPosition(CCPointZero);
    addChild(pSpriteBackground);
    // Scroll View
    char strLevel[100] = {0};
    CCMenu *pMenuLevel = CCMenu::create();
    
    
    for (int i = 0; i < numberOfLevel; i++) {
        sprintf(strLevel, "Level %d", i + 1);
        CCMenuItemLabel *pMenuLabel = CCMenuItemLabel::create(CCLabelTTF::create(strLevel, FONT_CONTENT, 32), this, menu_selector(ChooseLevelScene::selectLevel));
        pMenuLevel->addChild(pMenuLabel);
    }
    pMenuLevel->alignItemsVerticallyWithPadding(10);
    pMenuLevel->setPosition(CCPointMake(winSize.width/2, winSize.height/2));
    
    
    // Scroll View
    CCScrollView *pScrollView = CCScrollView::create(GameController::getWinSize());
    pScrollView->setPosition(CCPointZero);
    pScrollView->setTouchMode(kCCTouchesOneByOne);
    pScrollView->setDirection(kCCScrollViewDirectionVertical);
    pScrollView->setContainer(pMenuLevel);
    addChild(pScrollView);
    
    // Btn back
    CCMenuItemLabel *pBtnBack = CCMenuItemLabel::create(CCLabelTTF::create(STR_BACK, FONT_MENU, 56), this, menu_selector(ChooseLevelScene::backToMenu));
    // Menu
    CCMenu *pMenu = CCMenu::create(pBtnBack, NULL);
    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setPosition(CCPointMake(100, 64));
    addChild(pMenu);
    return true;
}

CCScene* ChooseLevelScene::scene() {
    CCScene *pScene = CCScene::create();
    ChooseLevelScene *pLayer = ChooseLevelScene::create();
    pScene->addChild(pLayer);
    return pScene;
}

ChooseLevelScene::~ChooseLevelScene() {
    
}


void ChooseLevelScene::selectLevel(CCObject *pSender) {
    GameController::replaceScene(GameScene::scene());
}